/*
 *  MiloSaveTextDatabase.cpp
 *  Milovo04alfa00
 *
 *  Created by Luca on 13/12/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "MilovoTables.h"

void SaveAgentsTable(Agents *, SimulationParams &, MilovoEnvironment &);
void SaveAgentsRelationships(Agents *, SimulationParams &, MilovoEnvironment &);	
void SaveRecipesTable(Recipes *, SimulationParams &, MilovoEnvironment &);
void SaveArtifactsTable(Artifacts *, SimulationParams &, MilovoEnvironment &);
void SaveMilovoEnvironmentTable(MilovoEnvironment &, SimulationParams &);
void PrintRecipesAgentsIntoFile(Agents *, Recipes *, Artifacts *, SimulationParams &, Mil_Int , int);
void SaveScaffoldingTable(ScaffoldingStructure *, SimulationParams &, MilovoEnvironment &);
void SaveAgentsStyle(Agents *, SimulationParams &, MilovoEnvironment &);
void SaveRequestsTable(Requests *, SimulationParams &, MilovoEnvironment &);

void SaveDataInTextDB(SimulationParams &tmpSimulaParam, Agents *CurrentTabAgents, Recipes *CurrentTabRecipes, Artifacts *CurrentTabArtifacts, 
							 Requests *CurrentTabRequests, ScaffoldingStructure *CurrentTabScaffolding, MilovoEnvironment &tmpM_Env)
{
	SaveAgentsTable(CurrentTabAgents, tmpSimulaParam, tmpM_Env);
	SaveAgentsStyle(CurrentTabAgents, tmpSimulaParam, tmpM_Env);
	SaveAgentsRelationships(CurrentTabAgents, tmpSimulaParam, tmpM_Env);	
	SaveRecipesTable(CurrentTabRecipes, tmpSimulaParam, tmpM_Env);
	SaveArtifactsTable(CurrentTabArtifacts, tmpSimulaParam, tmpM_Env);
	SaveMilovoEnvironmentTable(tmpM_Env, tmpSimulaParam);
	SaveScaffoldingTable(CurrentTabScaffolding, tmpSimulaParam, tmpM_Env);
	SaveRequestsTable(CurrentTabRequests, tmpSimulaParam, tmpM_Env);
//	PrintRecipesAgentsIntoFile(CurrentTabAgents, CurrentTabRecipes, CurrentTabArtifacts, tmpSimulaParam, tmpCurrentStep, tmpDebugLevel);
}	

void SaveAgentsTable(Agents *tmpCurrentTabAgents, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmp_M_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrCurrentTabAgentsDatFile = tmp_SimulaParam.GetWorkingDir() + "TabAgents_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabAgents(StrCurrentTabAgentsDatFile.c_str(), ios::out);
	
	fid_CurrentTabAgents << "ID\t" << "Activity\t" << "Goal\t" << "NumInnovationSucceded\t" << "NumInnovationSuccededWithPartner\t" 
		<< "NumInnovationFailed\t"	<< "NumInnovationFailedWithPartner\t" << "NumProjectsSucceded\t" << "NumProjectsFailed\t" 
		<< "NumTimeSelected\t" << "BornStep\t" << "Step" << endl;
	for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
		fid_CurrentTabAgents << tmpCurrentTabAgentsIter->second.GetID() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetActivity() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetGoal() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumInnovationSucceded() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumInnovationSuccededWithPartner() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumInnovationFailed() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumInnovationFailedWithPartner() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumProjectsSucceded() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumProjectsFailed() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetNumTimeSelected() << "\t"
			<< tmpCurrentTabAgentsIter->second.GetBornStep() << "\t"
			<< tmp_M_Env.GetCurrentStep() << endl;
	fid_CurrentTabAgents.close();
}

void SaveAgentsRelationships(Agents *tmpCurrentTabAgents, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmp_M_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrCurrentTabAgentsRelationshipsDatFile = tmp_SimulaParam.GetWorkingDir() + "TabAgentsRelationships_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabAgentsRelationships(StrCurrentTabAgentsRelationshipsDatFile.c_str(), ios::out);
	
	fid_CurrentTabAgentsRelationships << "ID\t" << "IDAgentPartner\t" << "DeltaTransactions\t" << "Transactions\t" << "DeltaProjects\t" 
		<< "Projects\t" << "Vote\t" << "AlignedDirectedness\t" << "Heterogeneity\t" << "GenerativePotential\t" << "KnowledgeDecay\t" 
		<< "Step" << endl;

	for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
	{
		for(Relationships::iterator TabRelationshipsIter = tmpCurrentTabAgentsIter->second.TabRelationships.begin(); TabRelationshipsIter != tmpCurrentTabAgentsIter->second.TabRelationships.end(); TabRelationshipsIter++)
		{
			fid_CurrentTabAgentsRelationships << tmpCurrentTabAgentsIter->second.GetID() << "\t" 
			<< TabRelationshipsIter->second.GetIDAgentPartner() << "\t"
			<< TabRelationshipsIter->second.GetDeltaTransactions() << "\t"
			<< TabRelationshipsIter->second.GetTransactions() << "\t"
			<< TabRelationshipsIter->second.GetDeltaProjects() << "\t"
			<< TabRelationshipsIter->second.GetProjects() << "\t"
			<< TabRelationshipsIter->second.GetVote() << "\t"
			<< TabRelationshipsIter->second.GetAlignedDirectedness() << "\t" 
			<< TabRelationshipsIter->second.GetHeterogeneity() << "\t" 
			<< TabRelationshipsIter->second.GetGenerativePotential() << "\t"
			<< TabRelationshipsIter->second.GetKnowledgeDecay() << "\t"
			<< tmp_M_Env.GetCurrentStep() << endl;
		}
	}
	fid_CurrentTabAgentsRelationships.close();
}

void SaveRecipesTable(Recipes *tmpCurrentTabRecipes, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmp_M_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrCurrentTabRecipesDatFile = tmp_SimulaParam.GetWorkingDir() + "TabRecipes_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabRecipes(StrCurrentTabRecipesDatFile.c_str(), ios::out);
	fid_CurrentTabRecipes << "ID\t" << "Status\t" << "IDAgent\t" << "NProduce\t" << "IDArtifactOutput\t" << "Step" << endl;
	
	string StrCurrentTabCompRecipesDatFile = tmp_SimulaParam.GetWorkingDir() + "TabCompRecipes_Step" + StrCurrentStep.str() + ".csv";
	ofstream fid_CurrentTabCompRecipes(StrCurrentTabCompRecipesDatFile.c_str(), ios::out);
	fid_CurrentTabCompRecipes << "IDRecipe\t" << "IDArtifact\t" << "Step" << endl;
	
	string StrCurrentTabCompOperatorsDatFile = tmp_SimulaParam.GetWorkingDir() + "TabCompOperators_Step" + StrCurrentStep.str() + ".csv";
	ofstream fid_CurrentTabCompOperators(StrCurrentTabCompOperatorsDatFile.c_str(), ios::out);
	fid_CurrentTabCompOperators << "IDRecipe\t" << "IDOperator\t" << "Step" << endl;

	for(Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->begin(); tmpCurrentTabRecipesIter != tmpCurrentTabRecipes->end(); tmpCurrentTabRecipesIter++)
	{
		fid_CurrentTabRecipes << tmpCurrentTabRecipesIter->second.GetID() << "\t" 
			<< tmpCurrentTabRecipesIter->second.GetStatus() << "\t" 
			<< tmpCurrentTabRecipesIter->second.GetIDAgentOwner() << "\t" 
		   << tmpCurrentTabRecipesIter->second.GetNProduce() << "\t" 
			<< tmpCurrentTabRecipesIter->second.GetIDArtifactOutput() << "\t" 
			<< tmp_M_Env.GetCurrentStep() << endl;
		
		for(list<Mil_Int>::iterator LinksIDInputsIter = tmpCurrentTabRecipesIter->second.LinksIDArtifacts.begin(); LinksIDInputsIter != tmpCurrentTabRecipesIter->second.LinksIDArtifacts.end(); LinksIDInputsIter++)
		{
			Mil_Int tmpIDInput = *LinksIDInputsIter;
			fid_CurrentTabCompRecipes << tmpCurrentTabRecipesIter->second.GetID() << "\t" << tmpIDInput << "\t" << tmp_M_Env.GetCurrentStep() << endl;
		}
		for(list<Mil_Int>::iterator LinksOperatorsIter = tmpCurrentTabRecipesIter->second.LinksOperators.begin(); LinksOperatorsIter != tmpCurrentTabRecipesIter->second.LinksOperators.end(); LinksOperatorsIter++)
		{
			Mil_Int tmpIDOperator = *LinksOperatorsIter;
			fid_CurrentTabCompOperators << tmpCurrentTabRecipesIter->second.GetID() << "\t" << tmpIDOperator << "\t" << tmp_M_Env.GetCurrentStep() << endl;
		}
	}
	fid_CurrentTabRecipes.close();
	fid_CurrentTabCompRecipes.close();
	fid_CurrentTabCompOperators.close();
}

void SaveArtifactsTable(Artifacts *tmpCurrentTabArtifacts, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmp_M_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrCurrentTabArtifactsDatFile = tmp_SimulaParam.GetWorkingDir() + "TabArtifacts_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabArtifacts(StrCurrentTabArtifactsDatFile.c_str(), ios::out);
	
	fid_CurrentTabArtifacts << "ID\t" << "Name\t" << "Status\t" << "IDAgent\t" << "Amount\t" << "AmountCeil\t" 
		<< "IDRecipe\t" << "Buyers\t" << "BornStep\t" << "Step" << endl;
	for(Artifacts::iterator CurrentTabArtifactsIter = tmpCurrentTabArtifacts->begin(); CurrentTabArtifactsIter != tmpCurrentTabArtifacts->end(); CurrentTabArtifactsIter++)
		fid_CurrentTabArtifacts << CurrentTabArtifactsIter->second.GetID() << "\t"
			<< CurrentTabArtifactsIter->second.GetName() << "\t"
			<< CurrentTabArtifactsIter->second.GetStatus() << "\t"
			<< CurrentTabArtifactsIter->second.GetIDAgentOwner() << "\t"
			<< CurrentTabArtifactsIter->second.GetAmount() << "\t"
			<< CurrentTabArtifactsIter->second.GetAmountCeil() << "\t"
			<< CurrentTabArtifactsIter->second.GetIDRecipeOwner() << "\t"
			<< CurrentTabArtifactsIter->second.GetNumBuyers() << "\t"
			<< CurrentTabArtifactsIter->second.GetBornStep() << "\t"
			<< tmp_M_Env.GetCurrentStep() << endl;
	fid_CurrentTabArtifacts.close();
}
	
void SaveMilovoEnvironmentTable(MilovoEnvironment &tmp_M_Env, SimulationParams &tmp_SimulaParam)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrMilovoEnvironmentDatFile = tmp_SimulaParam.GetWorkingDir() + "TabEnvironment_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_MilovoEnvironmentDatFile(StrMilovoEnvironmentDatFile.c_str(), ios::out);
	
	fid_MilovoEnvironmentDatFile << "InnovationSucceded\t" << "InnovationFailed\t" <<  "NumAgentsBorn\t" << "NumAgentsDeadByMarket\t" 
		<< "NumAgentsDeadByZeroRecipes\t" << "NumRecipesDeadByProduction\t" << "NumRecipesDeadByMarket\t" << "GrowProbability\t" << "Step" << endl;
	fid_MilovoEnvironmentDatFile << tmp_M_Env.GetNumInnovationSucceded() << "\t"
		<< tmp_M_Env.GetNumInnovationFailed() << "\t"
		<< tmp_M_Env.GetNumAgentsBorn() << "\t"
		<< tmp_M_Env.GetNumAgentsDeadByMarket() << "\t"
		<< tmp_M_Env.GetNumAgentsDeadByZeroRecipes() << "\t"
		<< tmp_M_Env.GetNumRecipesDeadByProduction() << "\t"
		<< tmp_M_Env.GetNumRecipesDeadByMarket() << "\t"
		<< tmp_M_Env.GetGrowProbability() << "\t"
		<< tmp_M_Env.GetCurrentStep() << endl;
	
	fid_MilovoEnvironmentDatFile.close();
}

void PrintRecipesAgentsIntoFile(Agents *tmpCurrentTabAgents, Recipes *tmpCurrentTabRecipes, Artifacts *tmpCurrentTabArtifacts, 
										  SimulationParams &tmp_SimulaParam, Mil_Int tmp_CurrentStep, int CurrentDebugLevel)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_CurrentStep;
	string StrCurrentPrintRecipesAgentsDatFile = tmp_SimulaParam.GetWorkingDir() + "PrintRecipesAgents_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentPrintRecipesAgents(StrCurrentPrintRecipesAgentsDatFile.c_str(), ios::out);
	
	for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
	{
		fid_CurrentPrintRecipesAgents << "AgentID: " << tmpCurrentTabAgentsIter->second.GetID() << endl;
		for(list<Mil_Int>::iterator LinkRecipesIter = tmpCurrentTabAgentsIter->second.LinkRecipes.begin(); LinkRecipesIter != tmpCurrentTabAgentsIter->second.LinkRecipes.end(); LinkRecipesIter++)
		{
			Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->find(*LinkRecipesIter);
			fid_CurrentPrintRecipesAgents << "\tRecipeID: " << tmpCurrentTabRecipesIter->second.GetID() << endl << "\t";
			for(list<Mil_Int>::iterator LinksIDArtifactsIter = tmpCurrentTabRecipesIter->second.LinksIDArtifacts.begin(); LinksIDArtifactsIter != tmpCurrentTabRecipesIter->second.LinksIDArtifacts.end(); LinksIDArtifactsIter++)
			{
				Mil_Int tmpIDArtifactToPrint = *LinksIDArtifactsIter;
				fid_CurrentPrintRecipesAgents << "\tIDArt" << tmpIDArtifactToPrint << "(";
				Artifacts::iterator tmpCurrentTabArtifactsIter = tmpCurrentTabArtifacts->find(*LinksIDArtifactsIter);
				if(tmpCurrentTabArtifactsIter != tmpCurrentTabArtifacts->end())
					fid_CurrentPrintRecipesAgents << tmpCurrentTabArtifactsIter->second.GetName() << ") [" << tmpCurrentTabArtifactsIter->second.GetIDAgentOwner() << "]";
				else fid_CurrentPrintRecipesAgents << "NA)";
			}
			fid_CurrentPrintRecipesAgents << endl;
		}
	}
	fid_CurrentPrintRecipesAgents.close();
}

void SaveScaffoldingTable(ScaffoldingStructure *tmpCurrentTabScaffolding, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmpCurrentM_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmpCurrentM_Env.GetCurrentStep();
	string StrCurrentTabScaffoldingDatFile = tmp_SimulaParam.GetWorkingDir() + "TabScaffolding_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabScaffolding(StrCurrentTabScaffoldingDatFile.c_str(), ios::out);
	
	fid_CurrentTabScaffolding << "IDAgent\t" << "Counter\t" << "Step" << endl;
	for(ScaffoldingStructure::iterator tmpCurrentTabScaffoldingIter = tmpCurrentTabScaffolding->begin(); tmpCurrentTabScaffoldingIter != tmpCurrentTabScaffolding->end(); tmpCurrentTabScaffoldingIter++)
		fid_CurrentTabScaffolding << tmpCurrentTabScaffoldingIter->second.GetIDAgent() << "\t"
			<< tmpCurrentTabScaffoldingIter->second.GetCounter() << "\t"
			<< tmpCurrentM_Env.GetCurrentStep() << endl;
	fid_CurrentTabScaffolding.close();
}

void SaveAgentsStyle(Agents *tmpCurrentTabAgents, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmp_M_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrCurrentTabAgentsDatFile = tmp_SimulaParam.GetWorkingDir() + "TabAgentsStyle_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabAgents(StrCurrentTabAgentsDatFile.c_str(), ios::out);
	
	fid_CurrentTabAgents << "ID\t" << "ProbImitation\t" << "ProbJump\t" << "StartJumpRange\t" << "EndJumpRange\t" << "JumpRangeUsed\t" 
		<< "ProbDevelopNewGoal\t" << "InnovationStrategy\t" << "SelectPartnerMode\t" << "UseSuppliersChange\t" << "HowManyNewFriends\t" 
		<< "KnowledgeDecay\t" << "IncludeZeroAgentInNewFriends\t" << "SelectGoalInAgentOutput\t" << "ProbGoalFromRequest\t" 
		<< "ValidateRecipeOutput\t" << "NProduceFloor\t" << "NProduceCeil\t" << "AlfaTransactions\t" << "BetaProjects\t" 
		<< "LambdaTransactions\t" << "LambdaProjects\t" << "ValueSuccessedProjects\t" << "ValueFailedProjects\t" << "ProjectsDeadLevel\t" 
		<< "MaxRecipesAllowed\t" << "ScaffProb\t" << "AcceptScaffMinLevel\t" << "UseDeepSearchGoal\t" << "ChangeSupplierMethod\t" 
	   << "ProduceRecipeMethod\t" << "Step" << endl;
	
	for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
		fid_CurrentTabAgents << tmpCurrentTabAgentsIter->second.GetID() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetProbImitation() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetProbJump() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetStartJumpRange() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetEndJumpRange() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetJumpRangeUsed() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetProbDevelopNewGoal() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetInnovationStrategy() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetSelectPartnerMode() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetUseSuppliersChange() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetHowManyNewFriends() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetKnowledgeDecay() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetIncludeZeroAgentInNewFriends() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetSelectGoalInAgentOutput() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetProbGoalFromRequest() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetValidateRecipeOutput() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetNProduceFloor() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetNProduceCeil() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetAlfaTransactions() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetBetaProjects() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetLambdaTransactions() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetLambdaProjects() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetValueSuccessedProjects() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetValueFailedProjects() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetProjectsDeadLevel() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetMaxRecipesAllowed() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetScaffProb() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetAcceptScaffMinLevel() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetUseDeepSearchGoal() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetChangeSupplierMethod() << "\t"
			<< tmpCurrentTabAgentsIter->second.Style.GetProduceRecipeMethod() << "\t"
		<< tmp_M_Env.GetCurrentStep() << endl;
	fid_CurrentTabAgents.close();
}

void SaveRequestsTable(Requests *tmpCurrentTabRequests, SimulationParams &tmp_SimulaParam, MilovoEnvironment &tmp_M_Env)
{
	ostringstream StrCurrentStep;
	StrCurrentStep << tmp_M_Env.GetCurrentStep();
	string StrCurrentTabRequestsDatFile = tmp_SimulaParam.GetWorkingDir() + "TabRequest_Step" + StrCurrentStep.str() + ".csv";	
	ofstream fid_CurrentTabRequestsDatFile(StrCurrentTabRequestsDatFile.c_str(), ios::out);
	
	fid_CurrentTabRequestsDatFile << "ID\t" << "ArtifactName\t" << "IDAgentOwner\t" << "RequestStep\t" << "Checked\t" 
		<< "IDAgentChecked\t"	<< "Step" << endl;
	for(Requests::iterator tmpCurrentTabRequestsIter = tmpCurrentTabRequests->begin(); tmpCurrentTabRequestsIter != tmpCurrentTabRequests->end(); tmpCurrentTabRequestsIter++)
	{
		fid_CurrentTabRequestsDatFile << tmpCurrentTabRequestsIter->second.GetID() << "\t"
			<< tmpCurrentTabRequestsIter->second.GetArtifactName() << "\t"
			<< tmpCurrentTabRequestsIter->second.GetIDAgentOwner() << "\t"
			<< tmpCurrentTabRequestsIter->second.GetRequestStep() << "\t";
		if(tmpCurrentTabRequestsIter->second.GetChecked() == true)
			fid_CurrentTabRequestsDatFile << "1\t";
		else fid_CurrentTabRequestsDatFile << "0\t";
		fid_CurrentTabRequestsDatFile << tmpCurrentTabRequestsIter->second.GetIDAgentChecked() << "\t"
			<< tmp_M_Env.GetCurrentStep() << endl;
	}
	
	fid_CurrentTabRequestsDatFile.close();
}


